﻿Imports Microsoft.Practices.EnterpriseLibrary.Logging


Partial Class _Default
    Inherits System.Web.UI.Page
    Const Category As String = "Login"

    Protected Sub Login_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login.Click
        XMLFile.ComputePercentage("Hatcoach", "de", Nothing, Nothing)
        Const Logtitle As String = "Login"
        Logger.Write(Logtitle & " -> Start.", Category, 10, 0, Diagnostics.TraceEventType.Verbose, Logtitle)
        Logger.Write("Checking password for user '" & EmailAddress.Text & "'.", Category, 10, 0, Diagnostics.TraceEventType.Verbose, Logtitle)
        Dim PasswordCorrect As String = XMLFile.CheckPassword(EmailAddress.Text.ToLower, Password.Text)
        If PasswordCorrect.Length = 0 Then
            Dim Logproperties As Dictionary(Of String, Object) = General.CreateLogProperties(EmailAddress.Text)
            Logger.Write("Logged in '" & EmailAddress.Text & "' successfully.", Category, 100, 0, Diagnostics.TraceEventType.Information, Logtitle, Logproperties)
            Session("User") = EmailAddress.Text
            Response.Redirect("Translate.aspx")
        Else
            Logger.Write("Error login user '" & EmailAddress.Text & "': " & PasswordCorrect, Category, 100, 0, Diagnostics.TraceEventType.Information, Logtitle)
            Session("ErrorMessage") = PasswordCorrect
            Response.Redirect("Error.aspx")
        End If

    End Sub

End Class
